<template>
	<view class="container">
		<view class="main">
			<view class="list">
				<view class="item" v-for="item in data">
					<view class="name_bg">
						<view class="name">{{item.name}}</view>
						<view class="desc">{{item.remark}}</view>
					</view>
					<view class="check">
						<image @click="select(item)" v-if="!item.checked" class="check-btn" src="../../static/images/check_normal.png"></image>
						<image @click="unselect(item)" v-else class="check-btn" src="../../static/images/check-selected.png"></image>
					</view>
				</view>
			</view><!-- list end -->
			
		</view><!--main end-->
		<view class="footer">
			<view class="submit-btn" @click="submitEvent()">确认选择</view>
		</view>
	</view>
</template>

<script>
	import {repair_list,publish} from '@/api/platform.js';
	export default {
		data() {
			return {
				data:[],
			}
		},
		onLoad() {
			this.getData();
		},
		created() {
			
		},
		methods: {
			//选择
			select(item){
				this.data.map(function(v){
					if(v.id == item.id){
						return v['checked'] = true;
					}else{
						return v;
					}
				});
			},
			unselect(item){
				this.data.map(function(v){
					if(v.id == item.id){
						return v['checked'] = false;
					}else{
						return v;
					}
				});
			},
			getData(){
				let that = this;
				uni.showLoading({
					title:'加载中...'
				});
				repair_list({}).then((res) => {
					let data = res.data.list;
					console.info(data);
					let datas = [];
					data.map(function(v){
						v['checked'] = false;
						datas.push(v);
					});
					that.data = datas;
					uni.hideLoading();
				});
			},
			submitEvent(){
				let seles = [];
				let sele_names = [];
				this.data.map(function(v){
					if(v.checked){
						seles.push(v.id);
						sele_names.push(v.name);
					}
				});
				if(seles.length == 0){
					uni.showToast({
						icon:'none',
						title:'请选择项目'
					})
					return;
				}
				
				let pages = getCurrentPages();
				let prevPage = pages[pages.length -2];
				prevPage.$vm.selectItems(seles.join(','),sele_names.join('、'));
				uni.navigateBack();
				
			}
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #f2f2f2;
	}
	.container{
		display: flex;
		flex-direction: column;
		.main{
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			padding-bottom: 0;  
			padding-bottom: constant(safe-area-inset-bottom);  
			padding-bottom: env(safe-area-inset-bottom); 
			margin-bottom: 100;
			
			.list{
				display: flex;
				flex-direction: column;
				.item{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					background-color: white;
					padding: 30rpx 30rpx;
					align-items: center;
					margin-bottom: 20rpx;
					.name_bg{
						display: flex;
						flex-direction: column;
						margin-right: 30rpx;
						.name{
							font-size: 30rpx;
							color: black;
						}
						.desc{
							margin-top: 15rpx;
							font-size: 24rpx;
							color: darkgray;
						}
					}
					.check{
						
						.check-btn{
							width: 60rpx;
							height:60rpx;
						}
					}
				}
			}
		}//main end
		
		.footer{
			height: 80rpx;
			width: 100%;
			position: fixed;
			right: 0;
			bottom: 0;
			left: 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			padding-bottom: 0;  
			padding-bottom: constant(safe-area-inset-bottom);  
			padding-bottom: env(safe-area-inset-bottom); 
			.submit-btn{
				background-color: $uni-main-color;
				color: white;
				font-size: 28rpx;
				height: 80rpx;
				width: 100%;
				text-align: center;
				line-height: 80rpx;
			}
		}// end footer
		/** 弹窗 **/
		.popup-cls{
			display: flex;
			flex-direction: column;
			.pop-info{
				width:100%;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				margin: 0 auto;
				background-color: white;
				.pop-top{
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					align-items: center;
					font-size: 28rpx;
					color: #000000;
					font-weight: bold;
					margin-top: 20rpx;
					text-align: center;
					height: 40rpx;
				}
			}
			
			.center{
				margin-top: 30rpx;
				width:100%;
				padding: 0rpx 0rpx;
				display: flex;
				flex-direction: column;
				.warning{
					color: darkorange;
					font-size: 28rpx;
					padding: 0 30rpx;
				}
				.pop-content{
					display: flex;
					flex-direction: column;
					height: 700rpx;
					margin-top: 30rpx;
					.list{
						display: flex;
						flex-direction: column;
						.top{
							display: flex;
							flex-direction: row;
							padding: 0 30rpx;
							.red{
								color: red;
							}
							.title{
								font-size: 28rpx;
								font-weight: bold;
								color: black;
							}
							.desc{
								font-size: 28rpx;
								color: gray;
							}
						}
						.bottom{
							display: flex;
							flex-direction: row;
							flex-wrap: wrap;
							margin-top: 20rpx;
							// padding-left: 10rpx;
							.item{
								color: black;
								height:70rpx;
								line-height: 70rpx;
								margin-left: 30rpx;
								font-weight: bold;
							}
							.item-body{
								display: flex;
								flex-direction: row;
								flex-wrap: wrap;
								margin-top: 20rpx;
								.item-i{
									width: 16%;
									background-color: #f2f2f2;
									color: black;
									text-align: center;
									height:60rpx;
									line-height: 60rpx;
									margin-bottom: 20rpx;
									border-radius: 10rpx;
									border: 1rpx solid #f2f2f2;
									margin-left: 20rpx;
								}
								.item_selected{
									border: 1rpx solid orange;
									background-color: blanchedalmond;
									color: orange;
								}
							}
							//不能选择
							.item_unselected{
								border: 1rpx solid #f2f2f2;
								background-color: #f2f2f2;
								color: gray;
							}
						}
					}
				}
				//pop-content
				.btn{
					background-color: $uni-main-color;
					color: white;
					font-size: 28rpx;
					height: 80rpx;
					width: 100%;
					text-align: center;
					line-height: 80rpx;
				}
			}//center
			
		}//popup-cls end
		
		/** 时间弹窗 **/
		.popup-cls2{
			display: flex;
			flex-direction: column;
			.pop-info{
				width:100%;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				margin: 0 auto;
				background-color: white;
				.pop-top{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					font-weight: bold;
					margin-top: 20rpx;
					text-align: center;
					padding-bottom: 30rpx;
					.cancel{
						font-size: 28rpx;
						color: dimgray;
						margin-left:30rpx;
						height: 60rpx;
						width: 130rpx;
						line-height: 60rpx;
					}
					.title{
						font-size: 30rpx;
						font-weight: bold;
					}
					.confirm{
						background-color: $uni-main-color;
						color: white;
						font-size: 28rpx;
						height: 60rpx;
						width: 130rpx;
						border-radius: 30rpx;
						line-height: 60rpx;
						margin-right:30rpx;
					}
				}
			}
			
			.center{
				width:100%;
				display: flex;
				flex-direction: column;
				.top_bg{
					background-color: oldlace;
					height: 80rpx;
					color: darkorange;
					font-size: 30rpx;
					line-height: 80rpx;
					padding-left: 30rpx;
				}
				.pop-content{
					padding: 0rpx 30rpx;
					display: flex;
					flex-direction: row;
					height: 500rpx;
					.left{
						width: 280rpx;
						background-color: #f8f8f8;
						.section{
							padding-left: 30rpx;
							height: 80rpx;
							color: black;
							font-size: 28rpx;
							background-color: transparent;
							line-height: 80rpx;
						}
						.selected{
							background-color: white;
							color: darkorange;
							font-weight: bold;
						}
					}
					.right{
						margin-left: 30rpx;
						flex: 1;
						background-color: white;
						.section{
							height: 80rpx;
							color: black;
							font-size: 28rpx;
							line-height: 80rpx;
						}
						.selected{
							background-color: white;
							color: darkorange;
							font-weight: bold;
						}
					}
				}
			}
			
		}//popup-cls2 end
	}
	
</style>
